/*
 * @Author: kanglang
 * @Date: 2021-01-12 20:03:16
 * @LastEditors: 汪滔
 * @LastEditTime: 2021-05-27 10:00:38
 * @Description: 录入人脸结果成功/失败
 */
import React from 'react';
import {
  View,
  StyleSheet,
  Image,
  Text,
  SafeAreaView,
  TouchableOpacity,
} from 'react-native';
import { msg } from '@/common';
import { px2dp } from '@/styles';
import { iconBigSuccessGreen, iconBigFailureOrange } from '@/images';

export default class UploadFaceResult extends React.Component {
  constructor(props) {
    super(props);
    const { navigation } = props;
    const state = navigation.state || {};
    const params = state.params || {};
    const { isSuccess, result = '未检测到人脸信息' } = params;
    this.state = {
      isSuccess: isSuccess,
      result: result,
    };
  }

  render() {
    const { isSuccess, result } = this.state;
    return (
      <SafeAreaView style={styles.safeViewStyle}>
        {isSuccess ? (
          <View style={styles.container}>
            <Image style={styles.img} source={iconBigSuccessGreen} />
            <Text style={styles.titleOne}>您的人脸信息已成功录入</Text>
            <Text styles={styles.titleTwo}>
              您可以刷脸登录缘多新联盟车载设备
            </Text>
            <TouchableOpacity
              activeOpacity={0.8}
              style={styles.submit}
              onPress={this.modifyFace}
            >
              <Text style={styles.titleThree}>修改人脸信息</Text>
            </TouchableOpacity>
          </View>
        ) : (
          <View style={styles.container}>
            <Image style={styles.img} source={iconBigFailureOrange} />
            <Text style={styles.titleOne}>
              非常抱歉，您的人脸识别信息未通过
            </Text>
            <Text styles={styles.titleTwo}>{`原因：${result}`}</Text>
            <TouchableOpacity
              activeOpacity={0.8}
              style={styles.submit}
              onPress={this.modifyFace}
            >
              <Text style={styles.titleThree}>重新录入</Text>
            </TouchableOpacity>
          </View>
        )}
      </SafeAreaView>
    );
  }

  modifyFace = () => {
    msg.emit('router: back');
  };
}

const styles = StyleSheet.create({
  safeViewStyle: {
    backgroundColor: '#fff',
  },
  container: {
    height: '100%',
    width: '100%',
    backgroundColor: '#fff',
    alignItems: 'center',
  },
  img: {
    width: px2dp(294),
    height: px2dp(294),
    marginTop: px2dp(64),
  },
  titleOne: {
    fontSize: px2dp(40),
    color: '#333232',
    marginTop: px2dp(17),
    marginBottom: px2dp(25),
  },
  titleTwo: {
    fontSize: px2dp(28),
    color: '#999896',
  },
  submit: {
    width: px2dp(320) * 2,
    height: px2dp(48) * 2,
    borderRadius: px2dp(16),
    marginTop: px2dp(104),
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#BA914A',
  },
  titleThree: {
    fontSize: px2dp(36),
    color: '#FFFFFF',
  },
});
